-- 删除已存在的表（按依赖关系逆序）
IF OBJECT_ID('dbo.t_sales', 'U') IS NOT NULL DROP TABLE dbo.t_sales;
IF OBJECT_ID('dbo.t_sales_targets', 'U') IS NOT NULL DROP TABLE dbo.t_sales_targets;
IF OBJECT_ID('dbo.t_training_records', 'U') IS NOT NULL DROP TABLE dbo.t_training_records;
IF OBJECT_ID('dbo.t_employee_history', 'U') IS NOT NULL DROP TABLE dbo.t_employee_history;
IF OBJECT_ID('dbo.t_products', 'U') IS NOT NULL DROP TABLE dbo.t_products;
IF OBJECT_ID('dbo.t_employees', 'U') IS NOT NULL DROP TABLE dbo.t_employees;
IF OBJECT_ID('dbo.t_departments', 'U') IS NOT NULL DROP TABLE dbo.t_departments;

/*
================================================================================
1. 部门表 (t_departments)
================================================================================
*/
CREATE TABLE dbo.t_departments (
    department_id_ INT IDENTITY(1,1) PRIMARY KEY,
    department_name_ NVARCHAR(100) UNIQUE NOT NULL,
    location_ NVARCHAR(100),
    budget_ DECIMAL(15,2) CHECK (budget_ >= 0),
    manager_id_ INT,
    created_at_ DATETIME2 DEFAULT GETDATE(),
    updated_at_ DATETIME2 DEFAULT GETDATE()
);

-- 添加扩展属性（表注释）
EXEC sys.sp_addextendedproperty 
    @name = N'MS_Description', 
    @value = N'部门信息表', 
    @level0type = N'SCHEMA', @level0name = N'dbo', 
    @level1type = N'TABLE', @level1name = N't_departments';

/*
================================================================================
2. 员工表 (t_employees)
================================================================================
*/
CREATE TABLE dbo.t_employees (
    employee_id_ INT IDENTITY(1,1) PRIMARY KEY,
    name_ NVARCHAR(50) NOT NULL,
    email_ NVARCHAR(100) UNIQUE NOT NULL,
    department_id_ INT NOT NULL,
    salary_ DECIMAL(10,2) NOT NULL CHECK (salary_ > 0),
    hire_date_ DATE NOT NULL,
    manager_id_ INT,
    status_ NVARCHAR(20) DEFAULT 'ACTIVE' CHECK (status_ IN ('ACTIVE', 'INACTIVE', 'TERMINATED')),
    created_at_ DATETIME2 DEFAULT GETDATE(),
    updated_at_ DATETIME2 DEFAULT GETDATE(),
    
    -- 外键约束
    CONSTRAINT FK_t_emp_dept FOREIGN KEY (department_id_) REFERENCES dbo.t_departments(department_id_),
    CONSTRAINT FK_t_emp_manager FOREIGN KEY (manager_id_) REFERENCES dbo.t_employees(employee_id_)
);

-- 添加表注释
EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'员工信息表', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N't_employees';

/*
================================================================================
3. 产品表 (t_products)
================================================================================
*/
CREATE TABLE dbo.t_products (
    product_id_ INT IDENTITY(1,1) PRIMARY KEY,
    product_name_ NVARCHAR(100) NOT NULL,
    category_ NVARCHAR(50),
    unit_price_ DECIMAL(10,2) NOT NULL CHECK (unit_price_ > 0),
    created_at_ DATETIME2 DEFAULT GETDATE(),
    updated_at_ DATETIME2 DEFAULT GETDATE()
);

-- 添加表注释
EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'产品信息表', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N't_products';

/*
================================================================================
4. 销售记录表 (t_sales)
================================================================================
*/
CREATE TABLE dbo.t_sales (
    sale_id_ INT IDENTITY(1,1) PRIMARY KEY,
    employee_id_ INT NOT NULL,
    product_id_ INT NOT NULL,
    sale_date_ DATE NOT NULL,
    amount_ DECIMAL(10,2) NOT NULL CHECK (amount_ > 0),
    quantity_ INT NOT NULL CHECK (quantity_ > 0),
    region_ NVARCHAR(50),
    created_at_ DATETIME2 DEFAULT GETDATE(),
    
    -- 外键约束
    CONSTRAINT FK_t_sales_emp FOREIGN KEY (employee_id_) REFERENCES dbo.t_employees(employee_id_),
    CONSTRAINT FK_t_sales_product FOREIGN KEY (product_id_) REFERENCES dbo.t_products(product_id_)
);

/*
================================================================================
5. 销售目标表 (t_sales_targets)
================================================================================
*/
CREATE TABLE dbo.t_sales_targets (
    target_id_ INT IDENTITY(1,1) PRIMARY KEY,
    employee_id_ INT NOT NULL,
    target_amount_ DECIMAL(12,2) NOT NULL CHECK (target_amount_ > 0),
    target_year_ INT NOT NULL,
    created_at_ DATETIME2 DEFAULT GETDATE(),
    updated_at_ DATETIME2 DEFAULT GETDATE(),
    
    -- 外键约束
    CONSTRAINT FK_t_target_emp FOREIGN KEY (employee_id_) REFERENCES dbo.t_employees(employee_id_) ON DELETE CASCADE,
    
    -- 唯一约束：每个员工每年只能有一个目标
    CONSTRAINT UK_t_emp_year UNIQUE (employee_id_, target_year_)
);

/*
================================================================================
6. 培训记录表 (t_training_records)
================================================================================
*/
CREATE TABLE dbo.t_training_records (
    training_id_ INT IDENTITY(1,1) PRIMARY KEY,
    employee_id_ INT NOT NULL,
    training_type_ NVARCHAR(100) NOT NULL,
    status_ NVARCHAR(20) DEFAULT 'Scheduled' CHECK (status_ IN ('Scheduled', 'In Progress', 'Completed', 'Cancelled')),
    start_date_ DATE,
    end_date_ DATE,
    created_at_ DATETIME2 DEFAULT GETDATE(),
    updated_at_ DATETIME2 DEFAULT GETDATE(),
    
    -- 外键约束
    CONSTRAINT FK_t_training_emp FOREIGN KEY (employee_id_) REFERENCES dbo.t_employees(employee_id_) ON DELETE CASCADE
);

/*
================================================================================
7. 员工历史记录表 (t_employee_history)
================================================================================
*/
CREATE TABLE dbo.t_employee_history (
    history_id_ INT IDENTITY(1,1) PRIMARY KEY,
    employee_id_ INT NOT NULL,
    action_type_ NVARCHAR(50) NOT NULL,
    action_date_ DATETIME2 DEFAULT GETDATE(),
    old_value_ NVARCHAR(MAX),
    new_value_ NVARCHAR(MAX),
    details_ NVARCHAR(MAX),
    created_by_ INT,
    
    -- 外键约束
    CONSTRAINT FK_t_history_emp FOREIGN KEY (employee_id_) REFERENCES dbo.t_employees(employee_id_) ON DELETE CASCADE
);

-- 添加部门管理者外键约束（在所有表创建后）
ALTER TABLE dbo.t_departments ADD CONSTRAINT FK_t_dept_manager 
    FOREIGN KEY (manager_id_) REFERENCES dbo.t_employees(employee_id_);

-- 创建索引
CREATE INDEX IX_t_emp_dept ON dbo.t_employees(department_id_);
CREATE INDEX IX_t_emp_manager ON dbo.t_employees(manager_id_);
CREATE INDEX IX_t_emp_hire_date ON dbo.t_employees(hire_date_);
CREATE INDEX IX_t_emp_status ON dbo.t_employees(status_);
CREATE INDEX IX_t_sales_emp ON dbo.t_sales(employee_id_);
CREATE INDEX IX_t_sales_product ON dbo.t_sales(product_id_);
CREATE INDEX IX_t_sales_date ON dbo.t_sales(sale_date_);
CREATE INDEX IX_t_sales_region ON dbo.t_sales(region_);

-- 插入部门数据
INSERT INTO dbo.t_departments (department_name_, location_, budget_) VALUES
('销售部', '合肥', 2500000.00),
('市场部', '北京', 1800000.00),
('技术部', '深圳', 3500000.00),
('人力资源部', '上海', 1200000.00),
('财务部', '杭州', 2000000.00),
('运营部', '成都', 1500000.00),
('客服部', '武汉', 1000000.00),
('研发部', '西安', 4000000.00),
('法务部', '南京', 800000.00),
('信息技术部', '广州', 1300000.00),
('质量保证部', '苏州', 900000.00),
('商务拓展部', '青岛', 1600000.00),
('产品管理部', '厦门', 2200000.00),
('数据分析部', '长沙', 1700000.00),
('安全部', '天津', 1100000.00);

-- 插入产品数据
INSERT INTO dbo.t_products (product_name_, category_, unit_price_) VALUES
('华为笔记本电脑', '电子产品', 6999.00),
('小米无线鼠标', '电子产品', 99.00),
('罗技机械键盘', '电子产品', 299.00),
('戴尔4K显示器', '电子产品', 1999.00),
('绿联USB-C扩展坞', '电子产品', 199.00),
('罗技高清摄像头', '电子产品', 299.00),
('索尼蓝牙耳机', '电子产品', 799.00),
('苹果手机保护壳', '配件', 99.00),
('小米充电宝', '电子产品', 149.00),
('支架平板电脑支架', '配件', 79.00),
('人体工学办公椅', '办公家具', 1299.00),
('升降办公桌', '办公家具', 2999.00),
('飞利浦台灯', '办公家具', 199.00),
('得力白板', '办公用品', 299.00),
('晨光笔记本套装', '办公用品', 39.00),
('英雄钢笔套装', '办公用品', 89.00),
('得力订书机', '办公用品', 29.00),
('科密碎纸机', '办公设备', 599.00),
('惠普打印机', '办公设备', 899.00),
('佳能扫描仪', '办公设备', 699.00),
('九阳咖啡机', '电器', 399.00),
('美的饮水机', '电器', 899.00),
('格兰仕微波炉', '电器', 499.00),
('海尔小冰箱', '电器', 799.00),
('小米空气净化器', '电器', 699.00),
('美的台式风扇', '电器', 199.00),
('海康威视监控摄像头', '安防', 399.00),
('德施曼智能门锁', '安防', 1299.00),
('消防器材灭火器', '安全', 199.00),
('医疗急救包', '安全', 99.00);

-- 插入员工数据
INSERT INTO dbo.t_employees (name_, email_, department_id_, salary_, hire_date_, manager_id_, status_) VALUES
-- 部门经理
('张伟', 'zhangwei@163.com', 1, 15000.00, '2024-01-15', NULL, 'ACTIVE'),
('李娜', 'lina@qq.com', 2, 14000.00, '2024-01-20', NULL, 'ACTIVE'),
('王强', 'wangqiang@sina.com', 3, 18000.00, '2024-01-10', NULL, 'ACTIVE'),
('刘敏', 'liumin@163.com', 4, 12000.00, '2024-01-25', NULL, 'ACTIVE'),
('陈杰', 'chenjie@qq.com', 5, 16000.00, '2024-01-30', NULL, 'ACTIVE'),
('杨丽', 'yangli@sina.com', 6, 13000.00, '2024-02-05', NULL, 'ACTIVE'),
('赵勇', 'zhaoyong@163.com', 7, 11000.00, '2024-02-10', NULL, 'ACTIVE'),
('黄芳', 'huangfang@qq.com', 8, 17000.00, '2024-02-15', NULL, 'ACTIVE'),
('周军', 'zhoujun@sina.com', 9, 12500.00, '2024-02-20', NULL, 'ACTIVE'),
('吴静', 'wujing@163.com', 10, 13500.00, '2024-02-25', NULL, 'ACTIVE'),
('徐磊', 'xulei@qq.com', 11, 12800.00, '2024-03-01', NULL, 'ACTIVE'),
('孙艳', 'sunyan@sina.com', 12, 14500.00, '2024-03-05', NULL, 'ACTIVE'),
('马超', 'machao@163.com', 13, 15500.00, '2024-03-10', NULL, 'ACTIVE'),
('朱红', 'zhuhong@qq.com', 14, 14800.00, '2024-03-15', NULL, 'ACTIVE'),
('胡斌', 'hubin@sina.com', 15, 13800.00, '2024-03-20', NULL, 'ACTIVE'),

-- 普通员工
('林峰', 'linfeng@163.com', 1, 8000.00, '2024-04-01', 1, 'ACTIVE'),
('何玲', 'heling@qq.com', 1, 7500.00, '2024-04-05', 1, 'ACTIVE'),
('郭涛', 'guotao@sina.com', 1, 8200.00, '2024-04-10', 1, 'ACTIVE'),
('高燕', 'gaoyan@163.com', 2, 7800.00, '2024-04-15', 2, 'ACTIVE'),
('罗鹏', 'luopeng@qq.com', 2, 8100.00, '2024-04-20', 2, 'ACTIVE'),
('梁雪', 'liangxue@sina.com', 2, 7600.00, '2024-04-25', 2, 'ACTIVE'),
('宋辉', 'songhui@163.com', 3, 12000.00, '2024-05-01', 3, 'ACTIVE'),
('唐梅', 'tangmei@qq.com', 3, 11500.00, '2024-05-05', 3, 'ACTIVE'),
('韩龙', 'hanlong@sina.com', 3, 12500.00, '2024-05-10', 3, 'ACTIVE'),
('冯霞', 'fengxia@163.com', 4, 6500.00, '2024-05-15', 4, 'ACTIVE'),
('于刚', 'yugang@qq.com', 4, 6800.00, '2024-05-20', 4, 'ACTIVE'),
('董莉', 'dongli@sina.com', 5, 9000.00, '2024-05-25', 5, 'ACTIVE'),
('薛飞', 'xuefei@163.com', 5, 8800.00, '2024-06-01', 5, 'ACTIVE'),
('范洁', 'fanjie@qq.com', 6, 7200.00, '2024-06-05', 6, 'ACTIVE'),
('邓伟', 'dengwei@sina.com', 6, 7400.00, '2024-06-10', 6, 'ACTIVE'),
('石娟', 'shijuan@163.com', 7, 6000.00, '2024-06-15', 7, 'ACTIVE'),
('姚斌', 'yaobin@qq.com', 7, 6200.00, '2024-06-20', 7, 'ACTIVE'),
('谭丽', 'tanli@sina.com', 8, 13000.00, '2024-06-25', 8, 'ACTIVE'),
('廖强', 'liaoqiang@163.com', 8, 12800.00, '2024-07-01', 8, 'ACTIVE'),
('金花', 'jinhua@qq.com', 9, 7000.00, '2024-07-05', 9, 'ACTIVE'),
('陆军', 'lujun@sina.com', 10, 8500.00, '2024-07-10', 10, 'ACTIVE'),
('夏敏', 'xiamin@163.com', 11, 7300.00, '2024-07-15', 11, 'ACTIVE'),
('蒋涛', 'jiangtao@qq.com', 12, 8600.00, '2024-07-20', 12, 'ACTIVE'),
('沈燕', 'shenyan@sina.com', 13, 9200.00, '2024-07-25', 13, 'ACTIVE'),
('卢鹏', 'lupeng@163.com', 14, 8900.00, '2024-08-01', 14, 'ACTIVE'),
('魏雪', 'weixue@qq.com', 15, 8300.00, '2024-08-05', 15, 'ACTIVE'),

('王小明', 'wangxiaoming@163.com', 1, 7800.00, '2024-08-10', 1, 'ACTIVE'),
('李晓华', 'lixiaohua@qq.com', 2, 8000.00, '2024-08-15', 2, 'ACTIVE'),
('张志强', 'zhangzhiqiang@sina.com', 3, 11800.00, '2024-08-20', 3, 'ACTIVE'),
('刘建国', 'liujianguo@163.com', 4, 6700.00, '2024-08-25', 4, 'ACTIVE'),
('陈美丽', 'chenmeili@qq.com', 5, 8900.00, '2024-09-01', 5, 'ACTIVE'),
('杨天宇', 'yangtianyu@sina.com', 6, 7500.00, '2024-09-05', 6, 'ACTIVE'),
('赵文博', 'zhaowenbo@163.com', 7, 6100.00, '2024-09-10', 7, 'ACTIVE'),
('黄思雨', 'huangsiyu@qq.com', 8, 12900.00, '2024-09-15', 8, 'ACTIVE'),
('周立伟', 'zhouliwei@sina.com', 9, 7100.00, '2024-09-20', 9, 'ACTIVE'),
('吴雨桐', 'wuyutong@163.com', 10, 8600.00, '2024-09-25', 10, 'ACTIVE'),

('John Smith', 'john.smith@company.com', 3, 13500.00, '2024-10-01', 3, 'ACTIVE'),
('Maria Garcia', 'maria.garcia@company.com', 8, 14200.00, '2024-10-05', 8, 'ACTIVE'),
('David Johnson', 'david.johnson@company.com', 1, 8500.00, '2024-10-10', 1, 'ACTIVE'),
('Sarah Wilson', 'sarah.wilson@company.com', 2, 8300.00, '2024-10-15', 2, 'ACTIVE'),
('Michael Brown', 'michael.brown@company.com', 3, 12200.00, '2024-10-20', 3, 'ACTIVE'),
('Emily Davis', 'emily.davis@company.com', 4, 6900.00, '2024-10-25', 4, 'ACTIVE'),
('Robert Miller', 'robert.miller@company.com', 5, 9100.00, '2024-11-01', 5, 'ACTIVE'),
('Jennifer Taylor', 'jennifer.taylor@company.com', 6, 7600.00, '2024-11-05', 6, 'ACTIVE'),
('William Anderson', 'william.anderson@company.com', 7, 6300.00, '2024-11-10', 7, 'ACTIVE'),
('Lisa Thomas', 'lisa.thomas@company.com', 10, 8700.00, '2024-11-15', 10, 'ACTIVE'),

-- 已离职员工
('曹辉', 'caohui@sina.com', 1, 7800.00, '2024-02-01', 1, 'TERMINATED'),
('彭梅', 'pengmei@163.com', 2, 7600.00, '2024-03-01', 2, 'TERMINATED'),
('潘龙', 'panlong@qq.com', 3, 11000.00, '2024-04-01', 3, 'INACTIVE'),
('田霞', 'tianxia@sina.com', 4, 6300.00, '2024-05-01', 4, 'TERMINATED'),
('蔡刚', 'caigang@163.com', 5, 8500.00, '2024-06-01', 5, 'INACTIVE');

-- 更新部门经理
UPDATE dbo.t_departments SET manager_id_ = 1 WHERE department_id_ = 1;
UPDATE dbo.t_departments SET manager_id_ = 2 WHERE department_id_ = 2;
UPDATE dbo.t_departments SET manager_id_ = 3 WHERE department_id_ = 3;
UPDATE dbo.t_departments SET manager_id_ = 4 WHERE department_id_ = 4;
UPDATE dbo.t_departments SET manager_id_ = 5 WHERE department_id_ = 5;
UPDATE dbo.t_departments SET manager_id_ = 6 WHERE department_id_ = 6;
UPDATE dbo.t_departments SET manager_id_ = 7 WHERE department_id_ = 7;
UPDATE dbo.t_departments SET manager_id_ = 8 WHERE department_id_ = 8;
UPDATE dbo.t_departments SET manager_id_ = 9 WHERE department_id_ = 9;
UPDATE dbo.t_departments SET manager_id_ = 10 WHERE department_id_ = 10;
UPDATE dbo.t_departments SET manager_id_ = 11 WHERE department_id_ = 11;
UPDATE dbo.t_departments SET manager_id_ = 12 WHERE department_id_ = 12;
UPDATE dbo.t_departments SET manager_id_ = 13 WHERE department_id_ = 13;
UPDATE dbo.t_departments SET manager_id_ = 14 WHERE department_id_ = 14;
UPDATE dbo.t_departments SET manager_id_ = 15 WHERE department_id_ = 15;

-- 生成销售数据（SQL Server版本）
DECLARE @counter INT = 1;
DECLARE @emp_id INT;
DECLARE @prod_id INT;
DECLARE @sale_date DATE;
DECLARE @amount DECIMAL(10,2);
DECLARE @quantity INT;
DECLARE @region NVARCHAR(50);
DECLARE @regions TABLE (region_name NVARCHAR(50));

INSERT INTO @regions VALUES ('North'), ('South'), ('East'), ('West'), ('Central'), ('Northeast'), ('Southeast'), ('Southwest'), ('Northwest');

WHILE @counter <= 2000
BEGIN
    -- 随机选择活跃员工
    SELECT TOP 1 @emp_id = employee_id_
    FROM dbo.t_employees
    WHERE status_ = 'ACTIVE'
    ORDER BY NEWID();

    -- 随机选择产品
    SELECT TOP 1 @prod_id = product_id_
    FROM dbo.t_products
    ORDER BY NEWID();

    -- 随机生成销售日期（2024年）
    SET @sale_date = DATEADD(DAY, ABS(CHECKSUM(NEWID())) % 365, '2024-01-01');

    -- 随机生成数量
    SET @quantity = ABS(CHECKSUM(NEWID())) % 20 + 1;

    -- 根据产品单价计算销售金额
    SELECT @amount = unit_price_ * @quantity * (0.8 + (ABS(CHECKSUM(NEWID())) % 100) / 250.0)
    FROM dbo.t_products
    WHERE product_id_ = @prod_id;

    -- 随机选择区域
    SELECT TOP 1 @region = region_name
    FROM @regions
    ORDER BY NEWID();

    -- 插入销售记录
    INSERT INTO dbo.t_sales (employee_id_, product_id_, sale_date_, amount_, quantity_, region_)
    VALUES (@emp_id, @prod_id, @sale_date, @amount, @quantity, @region);

    SET @counter = @counter + 1;
END;

-- 插入销售目标数据
INSERT INTO dbo.t_sales_targets (employee_id_, target_amount_, target_year_)
SELECT
    employee_id_,
    CASE
        WHEN salary_ >= 15000 THEN 500000.00
        WHEN salary_ >= 12000 THEN 300000.00
        WHEN salary_ >= 8000 THEN 150000.00
        ELSE 80000.00
    END,
    2024
FROM dbo.t_employees
WHERE status_ = 'ACTIVE' AND department_id_ IN (1, 2, 12, 13);

INSERT INTO dbo.t_sales_targets (employee_id_, target_amount_, target_year_)
SELECT
    employee_id_,
    CASE
        WHEN salary_ >= 15000 THEN 600000.00
        WHEN salary_ >= 12000 THEN 360000.00
        WHEN salary_ >= 8000 THEN 180000.00
        ELSE 96000.00
    END,
    2025
FROM dbo.t_employees
WHERE status_ = 'ACTIVE' AND department_id_ IN (1, 2, 12, 13);

-- 插入培训记录数据
INSERT INTO dbo.t_training_records (employee_id_, training_type_, status_, start_date_, end_date_) VALUES
(16, '新员工入职培训', 'Completed', '2024-04-01', '2024-04-03'),
(17, '新员工入职培训', 'Completed', '2024-04-05', '2024-04-07'),
(22, 'Java高级编程', 'Completed', '2024-05-01', '2024-05-15'),
(23, 'Python数据分析', 'Completed', '2024-05-05', '2024-05-19'),
(1, '高级管理技能', 'Completed', '2024-03-01', '2024-03-05'),
(2, '市场营销策略', 'Completed', '2024-03-10', '2024-03-14'),
(16, '销售技巧提升', 'Completed', '2024-06-01', '2024-06-05'),
(41, 'Business English', 'Completed', '2024-10-01', '2024-10-31');

-- 插入员工历史记录数据
INSERT INTO dbo.t_employee_history (employee_id_, action_type_, action_date_, old_value_, new_value_, details_) VALUES
(1, 'HIRED', '2024-01-15 09:00:00', NULL, 'Sales Manager', '张伟入职担任销售部经理'),
(2, 'HIRED', '2024-01-20 09:00:00', NULL, 'Marketing Manager', '李娜入职担任市场部经理'),
(1, 'SALARY_CHANGE', '2024-07-01 10:00:00', '15000.00', '16000.00', '年中绩效优秀，薪资上调'),
(16, 'PROMOTION', '2024-09-01 14:00:00', 'Sales Representative', 'Senior Sales Representative', '销售业绩优秀，晋升为高级销售代表'),
(46, 'TERMINATED', '2024-08-31 17:00:00', 'ACTIVE', 'TERMINATED', '曹辉主动离职');

-- 查看数据统计
SELECT 't_departments' as table_name, COUNT(*) as record_count FROM dbo.t_departments
UNION ALL
SELECT 't_employees', COUNT(*) FROM dbo.t_employees
UNION ALL
SELECT 't_products', COUNT(*) FROM dbo.t_products
UNION ALL
SELECT 't_sales', COUNT(*) FROM dbo.t_sales
UNION ALL
SELECT 't_sales_targets', COUNT(*) FROM dbo.t_sales_targets
UNION ALL
SELECT 't_training_records', COUNT(*) FROM dbo.t_training_records
UNION ALL
SELECT 't_employee_history', COUNT(*) FROM dbo.t_employee_history;